<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ page language="java" 
	import="java.util.*, com.bean.library.Term, com.bean.library.Course" %>
<jsp:useBean id="term" class = "com.bean.library.Term" scope="session"></jsp:useBean>
<jsp:useBean id="student" class = "com.bean.library.Student" scope="session"></jsp:useBean>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%
	HttpSession s = request.getSession();
	Course selectedCourse = (Course)s.getAttribute("selectedCourse");
	String studentName = student.getStuName();
%>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Free Practice</title>
    <link rel="stylesheet" href="../css/freeAnswer.css" type="text/css" />
    <link rel="stylesheet" href="../css/common.css" type="text/css" />
    <link rel="stylesheet" href="../css/left_course.css" type="text/css" />
    <script type="text/javascript" src="../scripts/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="../scripts/jquery.animate-colors-min.js"></script>
    <script type="text/javascript" src="../scripts/navi_common.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#choose_logo").hover(function () {
                $(this).animate({ backgroundColor: '#30A8F4' }, { speed: 1000, queue: false });
            }, function () {
                $(this).animate({ backgroundColor: '#C35A33' }, { speed: 1000, queue: false });
            });

            $('#btn_begin').hover(function () {
                $(this).animate({ backgroundColor: '#30A8F4' }, { speed: 1000, queue: false });
            }, function () {
                $(this).animate({ backgroundColor: '#C35A33' }, { speed: 1000, queue: false });
            });
            var li_count = parseInt($("#li_count").val(),10);
            if(li_count > 6){
            	var _height = li_count*10;
            	$("#content_exam").css("height",$("#content_left").css("height"));
            }else if($("#ui_need").val() == "need"){
            	$("#content_exam").css("height",$("#content_left").css("height"));
            }
        });
    </script>
</head>

<body>
<div id="bigContent">
<div id="head">
    <div id="title">
        <div class="title_left">
            <div class="titleText">Students Online Exam Platform</div>
        </div>
        <div class="title_right">
            <div class="avatar"><img src="../image/noavatar.jpg" alt="../image/noavatar.jpg"/></div>
            <div class="userState">
                <div class="userState_big"><a href="#"><%=studentName%></a></div>
                <div class="userState_small"><a href="/Exam1/servlet/SLogoutServlet">logout</a></div>
            </div>
        </div>
    </div>
    <form id="navi_form" action="/Exam1/servlet/SNaviSelectServlet">
	    <div id="navi">
	        <div class="navi_top">
	            <ul class="all_navi">
	            	<li id="navi1" class="each_navi navi1">Examination</li>
	                <li id="navi2" class="each_navi navi2">Practice Test </li>
	                <li id="navi3" class="each_navi navi3">Free Q&A</li>
	            </ul>
	        </div>
	        <div class="navi_bottom">
	            <ul class="all_terms">
	            	<li class="each_term term1">freshman 1</li>
	                <li class="each_term term2">freshman 2</li>
	                <li class="each_term term3">sophomore 1</li>
	                <li class="each_term term4">sophomore 2</li>
	                <li class="each_term term5">junior 1</li>
	                <li class="each_term term6">junior 2</li>
	            </ul>
	        </div>
	    </div>
       	<input type="hidden" value="" name="test_type" id="test_type"/>
        <input type="hidden" value="" name="which_term" id="which_term"/>
    </form>
</div>
<div id="content_exam"  class="boxShadow">
    <div id="choose_logo">
        <div class="choose_logo_text">Choose Your Subject And Begin Practice</div>
        <div class="choose_logo_img"></div>
    </div>
    <div id="content_left">
        <div id="courses">
            <div id="courses_title">Courses</div>
            <form id="course_form" action="/Exam1/servlet/SCourseSelectServlet" method="post">
	            <div id="courses_details">
	                <ul id="courses_list">
					<%
						ArrayList<Course> courseList = term.getCourseList();
						Iterator<Course> courseIt = courseList.iterator();
						int courseNum = 0;
						while(courseIt.hasNext()){
							courseNum++;
							Course course = (Course)courseIt.next();
							String courseName = course.getCourseName();
							String courseId = course.getCourseId();
					%>
	                	<li class="<%="li"+courseNum%>" id="<%=courseId%>"><div class="each_course_text"><%=courseName %></div></li>
	                <%} %>	
	                </ul>
	             	<input type="hidden" id="li_count" value="<%=courseNum%>"/>
	            </div>
	            <input type="hidden" value="" id="select_course" name="select_course"/>
	            <input type="hidden" value="" id="select_course_name" name="select_course_name"/>
	            <input type="hidden" value="free" id="test_type" name="test_type"/>
            </form>
        </div>
    </div>
    <div id="content_right">
    <%
    	if(selectedCourse!=null){
    		String selectedCourseName = selectedCourse.getCourseName();	
    		int[] eachRankNum = (int[])s.getAttribute("eachRankNum");
    %>
        <div id="subjects_name"><%=selectedCourseName %></div>
        <div id="free_answer">
            <div id="free_help" class="free_help">Please input the number of each 
            subject which has degree of difficulty ranks 1 to 5 and begin your practice</div>
            <div id="difficulty">
                <form action="/Exam1/servlet/GeneratePaperServlet" method="get">
                    <ul id="input_difficulty">
                	    <li>
                            <span>Rank1:<input type="text" name="rank1"/></span>
                            <span>(Total:<%=eachRankNum[1] %>)</span>
                        </li>
                        <li>
                            <span>Rank2:<input type="text" name="rank2"/></span>
                            <span>(Total:<%=eachRankNum[2] %>)</span>
                        </li>
                        <li>
                            <span>Rank3:<input type="text" name="rank3"/></span>
                            <span>(Total:<%=eachRankNum[3] %>)</span>
                        </li>
                        <li>
                            <span>Rank4:<input type="text" name="rank4"/></span>
                            <span>(Total:<%=eachRankNum[4] %>)</span>
                        </li>
                        <li>
                            <span>Rank5:<input type="text" name="rank5"/></span>
                            <span>(Total:<%=eachRankNum[5] %>)</span>
                        </li>
                    </ul>
                    <div id="begin_exam" class="begin_exam">
                        <input type="submit" id="btn_begin" value="Let's Begin"/>
                    </div>
                </form>
            </div>
        </div>
        <%}else{ %>
        <div id="subjects_name"><%="Please select a course first" %></div>
        <input type="hidden" id="ui_need" value="need"></input>        
        <%} %>
    </div>
    <div id="content_bottom"></div>   
</div>
</div>
</body>
</html>